package com.bsierp.util.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.bsierp.util.Constants;

public class UserLoginCheckFilter extends HttpServlet implements Filter {
    private FilterConfig filterConfig;
    //Handle the passed-in FilterConfig
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    public void doFilter(ServletRequest request, ServletResponse response,
                        FilterChain filterChain) {
       try
      {

          HttpServletRequest httpRequest = (HttpServletRequest) request;
          HttpServletResponse httpResponse = (HttpServletResponse) response;

          boolean isValid = false;

          if (httpRequest.getSession().getAttribute(Constants.userLogin_sessionindex) != null )
          {
              isValid = true;
          }
          if (isValid==true)
          {
              filterChain.doFilter(request, response);
          } else
          {
           httpResponse.sendRedirect(Constants.web_realpath+"/index.jsp");
              
        	 
          }
      } catch (ServletException sx)
      {
          filterConfig.getServletContext().log(sx.getMessage());
      } catch (IOException iox)
      {
          filterConfig.getServletContext().log(iox.getMessage());
      }

   }

    public void destroy() {
    }
}
